package com.shuoyue.ycgk.ui.main;

import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.AppVersionInfo;
import com.shuoyue.ycgk.entity.MainAdv;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import io.reactivex.Observable;

public interface VersionContract {
    interface View extends BaseView {

        void setAppVersion(AppVersionInfo version);
    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();

        public void getVersion() {
            apply(model.getVersion())
                    .subscribe(new ApiSubscriber<Optional<AppVersionInfo>>(mView, this) {
                        @Override
                        public void onNext(Optional<AppVersionInfo> option) {
                            super.onNext(option);
                            mView.setAppVersion(option.getIncludeNull());
                        }
                    });
        }
    }

    class Model {
        Observable<BaseResult<AppVersionInfo>> getVersion() {
            return RetrofitClient.getInstance().getApi().getVersion();
        }
    }
}
